package lcj.com.firstapp;

import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 鍔ㄧ敾娴嬭瘯Activity
 */
public class AnimatorDemo extends Activity {

    // 缂╂斁鍔ㄧ敾浣滅敤鐨凾extView
    private TextView tv_scaleAnimatorTarget;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animator_demo);
        tv_scaleAnimatorTarget = (TextView) findViewById(R.id.aty_animator_scale);
    }

    /**
     * 寮�濮嬬缉鏀惧姩鐢绘寜閽墽琛屾柟娉�
     *
     * @param v
     */
    public void clk_starScaleAnimator(View v) {
        // 鍒涘缓鍔ㄧ敾瀵硅薄锛堝彉鍖栫淮搴︽槸TextView鐨刋鏂瑰悜缂╂斁锛夛細
        // 鏈�鍚庡弬鏁�(1, 0, 2, 0, 1)鏄彲鍙樺弬鏁�(闅忎究浼犲叆澶氬皯涓��)锛岃〃绀轰粠澶氬皯鍙樺寲鍒板灏戯紝杩欓噷鏄粠鍘熷澶у皬(1)鍒�0锛屽啀鍒颁簩鍊嶅ぇ灏忥紝鍐嶅埌0锛屽啀鍒板師濮嬪ぇ灏�(1)
        ObjectAnimator scaleAnimator_x = ObjectAnimator.ofFloat(tv_scaleAnimatorTarget, View.SCALE_X, 1, 0, 2, 0, 1);
        // 涓哄姩鐢昏缃寔缁椂闂�
        scaleAnimator_x.setDuration(1000 * 2);
        // 寮�鍚姩鐢�
        scaleAnimator_x.start();

        // 鍒涘缓鍔ㄧ敾瀵硅薄锛堝彉鍖栫淮搴︽槸 TextView鐨刌鏂瑰悜缂╂斁锛�
        //鏈�鍚庣殑鍙傛暟鏄彲鍙樺弬鏁�(闅忎究浼犲叆澶氬皯涓��)锛岃〃绀轰粠澶氬皯鍙樺寲鍒板灏戯紝杩欓噷鏄粠鍘熷澶у皬(1)鍒�0锛屽啀鍒颁笁鍊嶅ぇ灏忥紝鍐嶅埌鍘熷澶у皬(1)
        ObjectAnimator scaleAnimator_y = ObjectAnimator.ofFloat(tv_scaleAnimatorTarget, View.SCALE_Y, 1, 0, 3 ,1);
        // 璁剧疆鍔ㄧ敾鐨勬寔缁椂闂�
        scaleAnimator_y.setDuration(1000 * 2);
        // 寮�鍚姩鐢�
        scaleAnimator_y.start();
    }

    /**
     * 寮�濮嬩綅绉诲姩鐢绘寜閽墽琛屾柟娉�
     * @param v
     */
    public void clk_startTransationAnimator(View v){

        // 鍒涘缓鍔ㄧ敾瀵硅薄锛堝彉鍖栫淮搴︽槸TextView鐨剎鏂瑰悜杩涜浣嶇Щ锛�
        // 鏈�鍚庣殑鍙傛暟0,200,-200,0琛ㄧず鐩稿浣嶇疆绉诲姩銆備粠鍘熷浣嶇疆(0)鍚慩杞存柟鍚戠Щ鍔ㄥ埌200鍍忕礌锛屽啀鍚慩杞存柟鍚戝弽鍚戠Щ鍔ㄥ埌-200鍍忕礌(鐩稿0鏉ヨ)锛屾渶鍚庡湪绉诲姩鍒板師濮嬩綅缃�(0)
        ObjectAnimator transation_x = ObjectAnimator.ofFloat(tv_scaleAnimatorTarget,View.TRANSLATION_X,0,200,-200,0);
        // 璁剧疆鍔ㄧ敾鎸佺画鏃堕棿
        transation_x.setDuration(1000 * 2);
        // 鍚姩鍔ㄧ敾
        transation_x.start();

        ObjectAnimator transation_y = ObjectAnimator.ofFloat(tv_scaleAnimatorTarget,View.TRANSLATION_Y,0,200,0);
        transation_y.setDuration(1000 * 2);
        transation_y.start();

    }

    /**
     * 寮�濮嬫棆杞姩鐢�
     * @param v
     */
    public void clk_startRotationAnimator(View v){

//        ObjectAnimator rotation_X = ObjectAnimator.ofFloat(tv_scaleAnimatorTarget,View.ROTATION_X,0,60,0);
//        rotation_X.setDuration(1000 * 2);
//        rotation_X.start();
//
//        ObjectAnimator rotation_Y = ObjectAnimator.ofFloat(tv_scaleAnimatorTarget,View.ROTATION_Y,0,60,0);
//        rotation_Y.setDuration(1000 * 2);
//        rotation_Y.start();
```
        ObjectAnimator rotation = ObjectAnimator.ofFloat(tv_scaleAnimatorTarget,View.ROTATION,0,180,0);
        rotation.setDuration(1000 * 2);
        rotation.start();
    }
    /**
     *动画监听器
     *
     * @param v
     */
    public void clk_listener(View v){
    	ObjectAnimator animator_x=ObjectAnimator.ofFloat(tv_scaleAnimatorTarget, View.TRANSLATION_X, values)
    /**
     *
     *
     * @param v
     */
	    public void clk_startAlphaAnimator(View v){
	        ObjectAnimator alpha = ObjectAnimator.ofFloat(tv_scaleAnimatorTarget,View.ALPHA,0,1);
	        alpha.setDuration(1000*2);
	        alpha.start();
	    }
	    /**
	     * 
	     * @param v
	     */
	    public void clk_overShootInteroolator(View v){
	    	ObjectAnimator animator_x=ObjectAnimator.ofFloat(tv_scaleAnimatorTarget, View.TRANSLATION_X, 0,200);
	    	animator_x.setDuration(1000*2);
	    	//设置动画监听器
	    	animator_x.addListener(new Animaotr.AnimatorListener){
	    		@Override
	    		public void onAnimatorStart(Animator animation){
	    			Toast.makeText(AnimatorDemo.this, "动画开始啦~~", Toast_LENGTH.SHORT).show();
	    			
	    		}
	    		@Override
	    		public void onAnimatorEnd(Animator animation){
	    			Toast.makeText(AnimatorDemo.this, "动画结束啦~~", Toast_LENGTH.SHORT).show();
	    		}
	    		@Override
	    		public void onAnimatorCancel(Animator animation){
	    		}
	    		@Override
	    		public void onAnimatorRepeat(Animator animation){
	    		}
	    	});
	    	animator_x.setRepeatCount(3);//设置动画重复次数，-1表示一直重复
	    	animator_x.start();
	    }
    }
}
